<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css"
          href="easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="easyui/demo/demo.css">
    <script type="text/javascript" src="myjs/path.js"></script>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script src="js/yangshi.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<shiro:lacksPermission name="vipzk:look">没有查询此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="vipzk:look">
    <div id="tb" style="padding: 5px; height: auto;">
        <div style="margin-bottom: 5px">
            <shiro:hasPermission name="vipzk:create">
                <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
                   onclick="openWin(0)">新增策略</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="vipzk:update">
                <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="openWin(1)">修改策略</a>
            </shiro:hasPermission>
        </div>
    </div>

    <div id="w" class="easyui-dialog"
         data-options="buttons:'#bb',modal:true,closed:true,iconCls:'icon-save',maximizable:false,minimizable:false,closable: false,collapsible:false"
         style="width: 350px; height: 180px; padding: 10px;">
        <input id="id" type="hidden">
        <table style="margin: 0 auto" cellpadding="8">
            <tr>
                <td>季节:</td>
                <td><select id="season"
                            data-options="panelHeight:'auto',editable:false"
                            style="width: 150px">

                </select><span style="color: red;"> *</span></td>
            </tr>
            <tr>
                <td>折扣:</td>
                <td><input id='zhekou' style="width: 150px"
                           class="easyui-validatebox easyui-textbox" data-options="prompt:'请输入折扣如：0.55'"><span
                        style="color: red;"> *</span></td>
            </tr>
        </table>
        <div id="bb">
            <button id="save" onclick="save()" href=""
                    class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存
            </button>
            <button onclick="$('#w').window('close')" href=""
                    class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消
            </button>
        </div>
    </div>


    <table id="dg"
           style="width: 100%; height: auto"></table>

</shiro:hasPermission>
</body>
</html>
<script>
    //修改
    function openWin(parm) {

        $('#season').combobox({
            url: path + '/production/findseasonzk.do',
            valueField: 'jijie',
            textField: 'jijie'
        });
        //新增
        if (parm == 0) {
            $("#id").val("");
            $("#season").combobox({readonly: false});
            $("#season").combobox("setValue", "");
            $("#zhekou").textbox("setValue", "");
            $('#w').dialog({title: "新增折扣策略"});
            $("#w").window("open");
        } else {
            //修改
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $("#season").combobox({readonly: true});
                $("#season").combobox("setValue", row.season);
                $("#zhekou").textbox("setValue", row.zhekou);

                $("#id").val(row.id);
                $('#w').dialog({title: "修改折扣策略"});
                $('#w').window('open');
            } else {
                $.messager.alert('警告', '请选择操作的数据');
            }
        }
    }
    function save() {
        var season = $("#season").combobox("getValue");
        var zhekou = $("#zhekou").val();
        var yzzk = /^(0.\d+|0|1)$/ // 判断是否为0-1的小数包括0
        if (season == "" || season == null) {
            $.messager.alert('警告', '请选择季节');
            return;
        }
        if (!yzzk.test(zhekou)) {
            $.messager.alert('警告', '请正确输入折扣');
            return;
        }
        $.ajax({
            url: path + '/zkseason/save.do',
            data: {
                season: season,
                zhekou: zhekou,
                id: $("#id").val()
            },
            dataType: 'json',
            success: function (data) {
                if (data.code == 200) {
                    $.messager.show({
                        title: '提示',
                        msg: '保存成功',
                        timeout: 3000,
                        showType: 'slide'
                    });
                    findAll();
                    $("#w").window("close");
                } else {
                    $.messager.alert('警告', data.msg);
                }
            }
        })
    }
    findAll();
    function findAll() {
        $("#dg").datagrid({
            url: path + '/zkseason/lsit.do',
            method: 'GET',
            toolbar: '#tb',
            fit: true,
            striped: true,
            singleSelect: true,
            autoRowHeight: true,
            rownumbers: true,
            nowrap: false,
            showFooter: true,
            loadMsg: '加载中,请稍后......',
            columns: [[{
                field: 'id',
                title: 'id',
                width: 50,
                align: 'left',
                hidden: true
            }, {
                field: 'season',
                title: '季节',
                width: 100,
                align: 'center'
            }, {
                field: 'zhekou',
                title: '折扣',
                width: 100,
                align: 'center',
                formatter: function (value) {
                    return value.toFixed(2);
                }
            }]],
        })
    }
</script>
